# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libdca
pkgbase=mingw-w64-${_realname}-svn
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-svn"
pkgver=r91
pkgrel=2
pkgdesc="Free library for decoding DTS Coherent Acoustics streams (mingw-w64)"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}" "${MINGW_PACKAGE_PREFIX}-libdts")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}" "${MINGW_PACKAGE_PREFIX}-libdts")
arch=('any')
url="https://www.videolan.org/developers/libdca.html"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "subversion")
options=('strip' 'staticlibs')
source=("${_realname}"::"svn://svn.videolan.org/libdca/trunk"
        0001-Proper-use-of-destdir.all.patch
        0002-fix-bootstrap.mingw.patch
        0003-fix-symlink.mingw.patch
        0004-fix-regex.all.patch
        0005-do-not-AC_C_ALWAYS_INLINE-it-redefines-inline-breaking-mingw-w64-GCC-5.1.0-C99.patch)
sha256sums=('SKIP'
            '3798f095105d0cbb0463aa9d63a567e4d61207fd777e2eaf48664482fd429421'
            'faa0bd12321fe8b93df11a6d331e6aee1c9ab9a1c3095f8b45b85cb7d30b3955'
            '18f674363ee357452352b315173193d844a5631b698958978e0b74520f75c77e'
            '5ec11ea54f0ce49d780daf31ac5b395290f41a8fbdd4726bbd884e5519b06a80'
            '7330924600dbe99cd22496702e8fb6799803cb210529771298f7291639aa7b5c')

pkgver() {
  cd "${srcdir}/${_realname}"
  local ver="$(svnversion)"
  printf "r%s" "${ver//[[:alpha:]]}"
}

prepare() {
  cd "${srcdir}/${_realname}"
  patch -p1 -i ${srcdir}/0001-Proper-use-of-destdir.all.patch
  patch -p1 -i ${srcdir}/0002-fix-bootstrap.mingw.patch
  patch -p1 -i ${srcdir}/0003-fix-symlink.mingw.patch
  patch -p1 -i ${srcdir}/0004-fix-regex.all.patch
  patch -p1 -i ${srcdir}/0005-do-not-AC_C_ALWAYS_INLINE-it-redefines-inline-breaking-mingw-w64-GCC-5.1.0-C99.patch

  autoreconf -fi
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --mandir=${MINGW_PREFIX}/share/man

  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install

  rm -f "${pkgdir}${MINGW_PREFIX}/share/man/man1"/{extract_dts,dtsdec}.1
  cp "${pkgdir}${MINGW_PREFIX}/share/man/man1/dcadec.1" "${pkgdir}${MINGW_PREFIX}/share/man/man1/dtsdec.1"
  cp "${pkgdir}${MINGW_PREFIX}/share/man/man1/extract_dca.1" "${pkgdir}${MINGW_PREFIX}/share/man/man1/extract_dts.1"
}
